package com.cy.pj.sys.service;

import com.cy.pj.sys.common.annotation.RequiredLog;
import com.cy.pj.sys.common.annotation.RequiredTime;
import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.pojo.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = false,timeout = 60,rollbackFor = Throwable.class)
@Service
public class SysLogServiceImpl implements SysLogService{
    @Autowired
    private SysLogDao sysLogDao;

    @Async //@Async注解描述的方法是一个异步切入点方法
    @Override
    public void saveLog(SysLog sysLog) {
        System.out.println("log.save.thread:"+Thread.currentThread().getName());
        sysLogDao.insertLog(sysLog);

    }

    @Transactional(readOnly = true)
    @RequiredTime()
    @RequiredLog(operation = "查询id")
    @Override
    public SysLog selectById(Long id) {
        System.out.println("log.select.thread:"+Thread.currentThread().getName());
        SysLog sysLog = sysLogDao.selectById(id);
        return sysLog;
    }


    @Transactional(readOnly = true)
    @RequiredLog(operation = "查询")
    @Override
    public List<SysLog> selectLogs(SysLog sysLog) {
        List<SysLog> sysLogs = sysLogDao.selectLogs(sysLog);
        return sysLogs;
    }

    @Transactional  //此注解描述的方法是一个事务控制方法
    @RequiredLog(operation = "删除操作")
    @Override
    public int deleteLogs(Long... id) {
        int row = sysLogDao.deleteLogs(id);
        return row;
    }


}
